package com.enpronomics.pcall.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.provider.Settings;
import android.view.WindowManager;

import com.enpronomics.pcall.MyLocation;
import com.enpronomics.pcall.ServiceManager;

public class DialogActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
		super.onCreate(savedInstanceState);
		Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
		// v.vibrate(2*1000);
		long[] pattern = { 0, 2000, 500, 2000 };// '0'=Start immediately
		v.vibrate(pattern, -1);// (-1 means "do not repeat")

		new AlertDialog.Builder(this)
				.setTitle("pCall")
				.setMessage("Open GPS?")
				.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						startActivity(new Intent(
								Settings.ACTION_LOCATION_SOURCE_SETTINGS));
						DialogActivity.this.finish();
					}
				})
				.setNegativeButton("Cancel",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								dialog.dismiss();
								DialogActivity.this.finish();
							}
						}).show();
		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				DialogActivity.this.finish();
			}
		}, MyLocation.OPEN_GPS_DELAY);
	}
}
